package com.xzbd.minio.vo;

import java.time.ZonedDateTime;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import io.minio.messages.Bucket;
import lombok.Builder;
import lombok.Getter;

/**
 * MinIO中Bucket的VO
 */
@Builder
@Getter
public class BucketVo {

    private String name;

    private ZonedDateTime creteDateTime;

    public static BucketVo fromBucket(Bucket bkt) {

        return BucketVo.builder()
                .name(bkt.name())
                .creteDateTime(bkt.creationDate())
                .build();
    }

    public static List<BucketVo> fromBucketList(List<Bucket> bks) {
        if (Objects.isNull(bks)) {
            return null;
        }
        return bks.stream().map(item -> fromBucket(item)).collect(Collectors.toList());
    }

}